/*
package common.filter;

import eu.bitwalker.useragentutils.UserAgent;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

*/
/**
 * Created by Administrator on 2016/7/28.
 *//*

*/
/*@WebFilter(value = {"*//*
*/
/*"}, dispatcherTypes = {DispatcherType.REQUEST}, asyncSupported = true)*//*

public class LoginFilter implements Filter {
    private static WebApplicationContext webApplicationContext;
    private static RedisTemplate<String, String> redisTemplate;

    public void init(FilterConfig filterConfig) throws ServletException {
        webApplicationContext = WebApplicationContextUtils.getWebApplicationContext(filterConfig.getServletContext());
        redisTemplate = (RedisTemplate<String, String>) webApplicationContext.getBean("redisTemplate");
        redisTemplate.boundValueOps("webapp").set(filterConfig.getServletContext().getRealPath("/"));
    }

    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        //保存用户访问信息
        HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;
        HttpServletResponse httpServletResponse = (HttpServletResponse) servletResponse;
        filterChain.doFilter(servletRequest, servletResponse);
        if (httpServletRequest.getCookies() == null) {
            String userAgentStr = httpServletRequest.getHeader("User-Agent");
            UserAgent userAgent = UserAgent.parseUserAgentString(userAgentStr);
            //统计用户访问平台量
            if (!("Unknown".equals(userAgent.getOperatingSystem().getName()) || "Unknown".equals(userAgent.getBrowser().getName()))) {
                String operatingSystem = userAgent.getOperatingSystem().getName();
                redisTemplate.boundHashOps("operatingSystem").put(operatingSystem, redisTemplate.boundHashOps("operatingSystem").get(operatingSystem) == null ? 1 : Integer.valueOf(redisTemplate.boundHashOps("operatingSystem").get(operatingSystem).toString()) + 1);
                redisTemplate.boundValueOps("operatingSystemTotal").set((redisTemplate.opsForValue().get("operatingSystemTotal") == null ? 1 : Integer.valueOf(redisTemplate.opsForValue().get("operatingSystemTotal").toString()) + 1) + "");
                String browser = userAgent.getBrowser().getName();
                redisTemplate.boundHashOps("browser").put(browser, redisTemplate.boundHashOps("browser").get(browser) == null ? 1 : Integer.valueOf(redisTemplate.boundHashOps("browser").get(browser).toString()) + 1);
                redisTemplate.boundValueOps("browserTotal").set((redisTemplate.opsForValue().get("browserTotal") == null ? 1 : Integer.valueOf(redisTemplate.opsForValue().get("browserTotal").toString()) + 1) + "");
            }
        }

    }

    public void destroy() {

    }

}
*/
